
#include <wiring.h>
#include <stdio.h>
#include <inttypes.h>
#include <NewSoftSerial.h>
#include "WString.h"
#include "./display.h"
#include "./status.h"



//extern scontroller Status;

#define maxCaratteriLinea 16//numero caratteri per linea
#define maxLinee  2 // numero massimo di linee
#define CLEAR 0xc //Form Feed - The cursor is moved to position 0 on line 0 and the entire display is cleared. Users must pause 5 ms after this command.
#define NEW_LINE 0xd //Carriage Return if on line 0 the cursor is moved to position 0 on line 1. If on line 1, it wraps around to position 0 on line 0.
#define DISP_OFF ox15 //display off
#define CUR_OFF_NO_BLK 0x16 //display on, with cursor off and no blink
#define CUR_OFF_CH_BLK 0x17   //display on, with cursor off and character blink
#define CUR_ON_NO_BLK 0x18   //display on, with cursor on and no blink (Default)
#define CUR_ON_CH_BLK 0x19   //display on, with cursor on and character blink

#define lcdcmd        0xFE   //command prefix
#define lcdcmd2      0x7C   //special command prefix
#define clrLCD        0x01   //Clear entire LCD screen
#define displayOff   0x08   //Display off
#define displayOn   0x0C   //Display on
#define noCurs       0x0C   //Make cursor invisible
#define ulCurs        0x0E   //Show underline cursor
#define blkCurs      0x0D   //Show blinking block cursor
#define curpos       0x80   //set cursor  + position  (row 1=0 to 15, row 2 = 64 to 79)
#define scrollRight 0x1C
#define scrollLeft   0x18
#define curRight    0x14
#define curLeft      0x10
int lcdPin=7;

NewSoftSerial magic = NewSoftSerial(6,7); // connect pin 7 to RX on the LCD

/**********************************************************************************/
display::display(){

}

void display::initDisplay() {
	
	magic.print(CLEAR,BYTE);
	delay(5);
	magic.print("INT= ?? T1=     ");    
	magic.print(NEW_LINE, BYTE);
	magic.print(NEW_LINE, BYTE);
	magic.print("EST= ?? T2=     ");    
} 


void display::start(long speed) {
  magic.begin(9600); // set up serial port for 9600 baud
  delay(1000);  
  magic.print(CLEAR,BYTE);
  delay(5);
  magic.print(CUR_OFF_NO_BLK, BYTE);
  magic.print("HI, I'M JARVIS! ");
  magic.print(NEW_LINE, BYTE);
  magic.print(NEW_LINE, BYTE);
  magic.print(" STARTING ...   ");
  delay(1000); 
}

void display::printIntTemp(unsigned int value){
      //magic.print(0x8c, BYTE);
	  //magic.print("+", BYTE);
	  magic.print(0x8d, BYTE);
	  magic.print(value, BYTE);
} 

void display::printExtTemp(unsigned int value){
      //magic.print(0xa0, BYTE);
	  //magic.print("+", BYTE);
	  magic.print(0xa1, BYTE);
	  magic.print(value, BYTE);
}

void display::printIntStatus(unsigned int connected){	
	if(connected==1){	
		//magic.print(0x86, BYTE);
		//magic.print("ON", BYTE);
	}else if(connected==0){
		//magic.print(0x86, BYTE);
		//magic.print("??", BYTE);
	}
}

void display::printExtStatus(unsigned int connected){	
	if(connected==1){	
		//magic.print(0x9a, BYTE);
		//magic.print("ON", BYTE);
	}else if(connected==0){
		//magic.print(0x9a, BYTE);
		//magic.print("??", BYTE);
	}
}

/*




void display::printStInt(unsigned int value){
  if (Status.getsDetect()==DISCONNECTED) {
    display.print(0x84,BYTE);
    display.print("-.-");
   }  
   else {
    if (value<1023) {
      display.print(0x84,BYTE);
      float fval = value/256.0;
      printDouble(fval,0);
    }  
   }  
} 

void display::printTR(unsigned int value){
  if (value>0) {
     if (value<1024) {
        display.print(0x8d,BYTE);
        float fval = value/256.0;
        printDouble(fval,1);   
     }
   }  
   else {
      display.print(0x8c,BYTE);
      display.print("-.-");
   }  
} 

void presentation::printS1(unsigned int value){
  if (Status.getsSwA()==DISCONNECTED) {
      display.print(0x98,BYTE);
      display.print("-.-");
   }  
   else {
    if (value<1024) {
      display.print(0x98,BYTE);
      float fval = value/256.0;
      printDouble(fval,1);   
    }  
   }  
} 


void display::printS2(unsigned int value){
  if (Status.getsSwB()==DISCONNECTED) {
      display.print(0xA0,BYTE);
      display.print("-.-");
  }  
  else {
    if (value<1024) {
      display.print(0xA0,BYTE);
      float fval = value/256.0;
      printDouble(fval,1);   
    }  
  }  
} 

void presentation::execute(){
//  if (Status.getsDetect()==DISCONNECTED) {
//      printPW(-1);  
//  }
//  else {
//      printPW(Status.getaDetect());
//  }  
//  printTR(Status.getaTreshold());
//  if (Status.getsSwA()==DISCONNECTED) {
//      printS1(-1);
//  }
//  else {  
//      printS1(Status.getaSwA());
//  }
//  if (Status.getsSwB()==DISCONNECTED) {
//      printS2(-1);
//  }
//  else {  
//      printS2(Status.getaSwB());
//  }
}  

*/



